home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Celestin Apprentice 5
/
Apprentice-Release5.iso
/
Source Code
/
By the Book
/
Learn C++ (CodeWarrior)
/
Chap 07.06 - smartPtr
/
smartPtr.cp
< prev
next >
Wrap
Text File
|
1995-10-20
|
1KB
|
67 lines
#include <iostream.h>
#include <string.h>
const short kMaxNameLength = 40;
//--------------------------------------- Name
class Name
{
private:
char first[ kMaxNameLength ];
char last[ kMaxNameLength ];
public:
Name( char *lastName, char *firstName );
void DisplayName();
};
Name::Name( char *lastName, char *firstName )
{
strcpy( last, lastName );
strcpy( first, firstName );
}
void Name::DisplayName()
{
cout << "Name: " << first << " " << last;
}
//--------------------------------------- Politician
class Politician
{
private:
Name *namePtr;
short age;
public:
Politician( Name *namePtr, short age );
Name *operator->();
};
Politician::Politician( Name *namePtr, short age )
{
this->namePtr = namePtr;
this->age = age;
}
Name *Politician::operator->()
{
return( namePtr );
}
//--------------------------------------- main()
int main()
{
Name myName( "Clinton", "Bill" );
Politician billClinton( &myName, 46 );
billClinton->DisplayName();
return 0;
}